/*
 * File Name: ExitAction.java
 * Created on: 
 */

package co.edu.uniandes.intercon.client.action;

import java.util.Map;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import co.edu.uniandes.intercon.client.gui.util.MessageHelper;
import co.edu.uniandes.intercon.server.networking.UDPReceiver;
import co.edu.uniandes.intercon.server.networking.UDPSender;

/**
 * Action used to exit the main window
 * @author Fabian Gutierrez [fagossa@gmail.com]
 */
public class ExitAction extends AbstractBaseGUIAction {
    
    /**
     * @see AbstractBaseGUIAction#execute(Map)
     */
    public Object execute(Map<String, Object> params) throws RuntimeException {
        JFrame window = (JFrame) params.get("window");
        
        int result = MessageHelper.showConfirmationDialog("desea salir?");
        if (result==JOptionPane.OK_OPTION ) {
            window.setVisible(false);
            
            UDPReceiver.release();
            UDPSender.release();
            
            window.dispose();
        }
        return null;
    }
  
}
